/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.exam;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: javaseapp - Demo
 * <p>Powered by webrx On 2021-08-18 08:44:33
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Demo {


    public static void main(String[] args) {

        //System.out.println(FileUtils.getFileType("D:\\abc\\images\\ab2.jpg"));

        //var iu = new ImgUtils();
        //iu.setWaterMaskText("版权所有", "rand", 8, 50, "font/zh210gfsnt.ttf", false);
        //iu.setWaterMaskText("北游教育 版权所有", 5);

        //iu.setWaterMaskText("d:/abc", "北游教育 版权所有", 0);

        //System.out.println(FileUtils.isImage("d:/abc/images/o1.jpg"));

        //var iu = new ImgUtils("d:/abc/images/abc.png");
        //iu.setWaterMaskLogo("d:/abc/images/logo.png", 8, true);
        //iu.jcrop(50, 50, 200, 200, false, "200_200");

        var iu = new ImgUtils("d:/abc/images/o1.jpg");
        iu.sizeTo(200, 150, false, "_a1");
        iu.sizeTo(.5, false, "_a2");
        iu.sizeTo(200, false, "_a3");
    }

    public static void m6(String[] args) {
        var map = FileUtils.countJdk("D:\\jdk\\jdk-16.0.2\\lib\\src");
        var list = new ArrayList<Word>();
        for (String key : map.keySet()) {
            list.add(new Word(key, map.get(key)));
        }
        list.sort((a, b) -> b.getCount() - a.getCount());
        for (int i = 0; i < 100; i++) {
            var w = list.get(i);
            System.out.println(w);
        }
    }

    public static void m5(String[] args) {
        var m = new TreeMap<String, Integer>();
        m.put("java", 1);
        m.put("php", 2);
        m.put("javascript", 5);

        System.out.println(m);
    }

    public static void m4(String[] args) {
        var map = FileUtils.countJdk("D:\\jdk\\jdk-16.0.2\\lib\\src");
        System.out.println(map.size());
        int i = 0;
        int u = 0;
        StringBuilder sbu = new StringBuilder();
        for (String k : map.keySet()) {
            i++;
            sbu.append(k + " ");
            if (i >= 2000) {
                i = 0;
                try (var br = new BufferedWriter(new FileWriter("d:/java/java" + ++u + ".txt"))) {
                    br.write(sbu.toString());
                    sbu.delete(0, sbu.length());
                } catch (Exception e) {

                }
            }
        }
    }

    public static void m3(String[] args) {
        String t = "D:\\ftp\\javase\\javaseapp\\09part\\src\\cn\\exam\\FileUtils.java";
        StringBuilder sbu = new StringBuilder();
        int rows = 0;
        try (var br = new BufferedReader(new FileReader(t))) {
            while (br.ready()) {
                //sbu.append(String.format("%03d %s%n", ++rows, br.readLine()));
                sbu.append(br.readLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        //System.out.println(sbu);

        Pattern pattern = Pattern.compile("[a-zA-Z]{2,}");
        Matcher m = pattern.matcher(sbu.toString());
        var map = new HashMap<String, Integer>();
        while (m.find()) {
            String w = m.group();
            if (map.containsKey(w)) {
                map.put(w, map.get(w) + 1);
            } else {
                map.put(w, 1);
            }

        }
        System.out.println(map.size());
        System.out.println(map);
    }


    public static void m2(String[] args) {
        //File file = new File("images");


        //System.out.println(FileUtils.getFileType("d:/09partm-1.0.jar"));

        //FileUtils.copyFile("images/o1.jpg", "images/o1111.jpg");

        FileUtils.copyDir("d:/abc", "d:/abcuuu");

    }


    public static void m1(String[] args) {
        //var fu = new FileUtils();
        //System.out.println(fu.count(new File("D:\\jdk\\jdk-16.0.2\\lib\\src"), "java"));

        //System.out.println(FileUtils.count(".", "jpg"));

        //System.out.println(FileUtils.list(new File(".")));

        //FileUtils.delDir("d:/userabc");

        //int i = 3;
        //System.out.println(FileUtils.countDirRows(new File(".")));
        //System.out.println(FileUtils.countDirRows(new File("D:\\jdk\\jdk-16.0.2\\lib\\src")));


        long start = System.currentTimeMillis();
        if (FileUtils.isOk(new File("d:/a.exe"), new File("d:/b.exe"))) {
            System.out.println("是同一个文件");
        } else {
            System.out.println("不是同一个文件");
        }
        System.out.println(System.currentTimeMillis() - start);

        long ss = System.currentTimeMillis();
        if (FileUtils.isSames(new File("d:/a.exe"), new File("d:/b.exe"))) {
            System.out.println("是同一个文件");
        } else {
            System.out.println("不是同一个文件");
        }
        System.out.println(System.currentTimeMillis() - ss);
        //System.out.println(FileUtils.countSourceRows(new File("D:\\ftp\\javase\\javaseapp\\09part\\src\\cn\\exam\\FileUtils.java")));
    }
}
